#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	int n, s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		int dx, dy, x, y;
		cin >> dx >> dy >> x >> y;
		if ((dx == -1 && dy == -1) || (dx == 1 && dy == 1))
		{
			if (x == y) ans++;
		}
		else
		{
			if (x + y == s) ans++;
		}
	}
	cout << ans << '\n';
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}